let timer = null;
const maxNoticeNum = 30;
let noticeNum = maxNoticeNum;

/** 重置提示 */
function resetNoticeNum() {
	clearInterval(timer);
	noticeNum = maxNoticeNum;
}

/** 网络状态监听 */
export default {
	onLaunch() {
		uni.onNetworkStatusChange(res => {
			// 网络回复
			if (res.isConnected) {
				console.debug('网络恢复')
				resetNoticeNum();
			}
			// 断网
			else timer = setInterval(() => {
				noticeNum--;
				if (noticeNum > 0)
					uni.showToast({ title: '网络链接异常请重新链接', icon: 'none' })
				else resetNoticeNum();
			}, 3000);
		});
	}
}